import java.io.IOException;

public class FileOperatorTester {

	private static final int ROWS = 20;
	private static final int COLUMNS = 25;
	private static final boolean VERBOSE = false;

	public static void main(String[] args) throws IOException {
		FileOperator fileops = new FileOperator("./storage/");

		long start = System.nanoTime();
		
		for (int i = 1; i <= 1500; i++) {
			genTheaterTester(i, ROWS, COLUMNS, fileops); //190.5 us (medium time for 1 file)
			getTheaterTester(i, fileops, VERBOSE); //443.3 us (medium time for 1 file)
			listTheatersTester(i, fileops, VERBOSE); //124.1 us (medium time for 1 file)
			reserveSeatTester(i, 2, 25, fileops, VERBOSE); //304.8 us (medium time for 1 file)
			purchaseSeatTester(i, 0, 1, fileops, VERBOSE); //304.8 us (medium time for 1 file)
			deleteTheaterTester(i, fileops, VERBOSE); //29.8 us (medium time for 1 file)
		}
		
		long time = System.nanoTime() - start;
        System.out.printf("Operations took an average of %.1f us%n", time / 1 / 1000.0);
	}

	public static void genTheaterTester(int id, int rows, int columns,
			FileOperator fileops) throws IOException {
		fileops.genTheater(id, rows, columns);
	}

	public static void getTheaterTester(int id, FileOperator fileops,
			boolean verbose) throws IOException {
		Teatro teatro = fileops.getTheater(id, COLUMNS);

		if (verbose) {
			int i = 0;

			System.out.println("ID: " + teatro.id);
			System.out.println("Nome: " + teatro.nome);
			System.out.println("Total de Lugares: " + teatro.lugaresTotal);
			System.out.println("Lugares Ocupados: " + teatro.lugaresOcupados
					+ "\n");
			for (Lugar seat : teatro.lugares) {
				i++;
				System.out.print("ID:" + seat.id + " ");
				System.out.print("Line:" + seat.row + " ");
				System.out.print("Col:" + seat.column + " ");
				System.out.println("State:" + seat.state);
			}
			System.out.println(i);
		}
	}

	public static void deleteTheaterTester(int id, FileOperator fileOps,
			boolean verbose) {

		if (verbose)
			if (fileOps.deleteTheater(id))
				System.out.println("Teatro" + id + ".txt sucessfully deleted");
			else
				System.out.println("Error on deletion of file: " + "Teatro"
						+ id + ".txt");
		else
			fileOps.deleteTheater(id);

	}

	public static void listTheatersTester(int id, FileOperator fileOps,
			boolean verbose) throws IOException {

		if (verbose)
			System.out.println(fileOps.getTheaterName(id));
		else
			fileOps.getTheaterName(id);
	}

	public static void reserveSeatTester(int id, int line, int column,
			FileOperator fileOps, boolean verbose) throws IOException {

		if (verbose)
			System.out.println(fileOps.reserveSeat(id, line, column));
		else
			fileOps.reserveSeat(id, line, column);
	}

	public static void purchaseSeatTester(int id, int line, int column,
			FileOperator fileOps, boolean verbose) throws IOException {

		if (verbose)
			System.out.println(fileOps.purchaseSeat(id, line, column));
		else
			fileOps.purchaseSeat(id, line, column);
	}
}
